package com.gd.iot.energy.controller.dailymanage;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.consts.SystemConsts;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.systemadmin.dto.AreaArchivesSaveDTO;
import com.gd.iot.energy.pojo.systemadmin.vo.AreaArchivesPageVO;
import com.gd.iot.energy.pojo.systemadmin.vo.AreaArchivesVO;
import com.gd.iot.energy.service.dailymanage.CustomerFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 日常管理-营业收费-收费客户
 *
 * @author kris
 * @date Created at 2020/8/7 10:50
 */
@Api(value = "日常管理-营业收费-收费客户/退费客户/余额查询",tags = "日常管理-营业收费-收费客户/退费客户/余额查询")
@RestController
@RequestMapping("/admin/customerFee")
public class CustomerFeeController {

    @Autowired
    private CustomerFeeService customerFeeService;

    @ApiOperation("客户缴费管理分页列表")
    @SystemLogRecordMonitor("客户缴费管理分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerPhone", value = "手机号码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "所属区域", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<AreaArchivesPageVO>> getPageList(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "customerPhone",required = false)String customerPhone,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<AreaArchivesPageVO> pageVO = customerFeeService.getAreaArchivesVOPage(customerSerialnumber,customerName,customerPhone,areaId,pageSize,pageNum,orderColumn,orderType, SystemConsts.QueryFeeType.COMMON,null);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取缴费信息")
    @SystemLogRecordMonitor("获取缴费信息")
    @PostMapping("/get")
    public ResponseEntity<AreaArchivesVO> get(Long id){
        AreaArchivesVO areaArchivesVO = customerFeeService.getAreaArchive(id);
        return new ResponseEntity<>(areaArchivesVO);
    }


    @ApiOperation("保存缴费")
    @SystemLogRecordMonitor("更新缴费")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody AreaArchivesSaveDTO areaArchivesSaveDTO){
        boolean res = customerFeeService.updateAreaArchive(areaArchivesSaveDTO, SystemConsts.ChargeType.pay);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("保存退费")
    @SystemLogRecordMonitor("保存退费")
    @PostMapping("/refund")
    public ResponseEntity<Boolean> refund(@RequestBody AreaArchivesSaveDTO areaArchivesSaveDTO){
        boolean res = customerFeeService.updateAreaArchive(areaArchivesSaveDTO,SystemConsts.ChargeType.refund);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("余额查询")
    @SystemLogRecordMonitor("余额查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerPhone", value = "手机号码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerFee", value = "余额少于", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "所属区域", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getBalance")
    public ResponseEntity<PageVO<AreaArchivesPageVO>> getBalance(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "customerPhone",required = false)String customerPhone,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "customerFee",required = false)String customerFee,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<AreaArchivesPageVO> pageVO = customerFeeService.getAreaArchivesVOPage(customerSerialnumber,customerName,
                customerPhone,areaId,pageSize,pageNum,orderColumn,orderType, SystemConsts.QueryFeeType.BALANCE_QUERY,customerFee);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("欠费查询")
    @SystemLogRecordMonitor("欠费查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerPhone", value = "手机号码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "所属区域", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getArrears")
    public ResponseEntity<PageVO<AreaArchivesPageVO>> getArrears(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "customerPhone",required = false)String customerPhone,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<AreaArchivesPageVO> pageVO = customerFeeService.getAreaArchivesVOPage(customerSerialnumber,customerName,
                customerPhone,areaId,pageSize,pageNum,orderColumn,orderType, SystemConsts.QueryFeeType.ARREARS_QUERY, "0");
        return new ResponseEntity<>(pageVO);
    }
}
